<template>
  <div>
    <el-row :gutter="20" class="topRow">
      <el-col :span="6">
        <div class="grid-content bg-purple">
          <el-tag type="success">销售额</el-tag>
          <div class="inNumber">4645</div>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="grid-content bg-purple">
          <el-tag type="warning">用户访问量</el-tag>
          <div class="inNumber">358841</div>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="grid-content bg-purple">
          <el-tag type="danger">订单量</el-tag>
          <div class="inNumber">6355</div>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="grid-content bg-purple">
          <el-tag type="info">新增用户</el-tag>
          <div class="inNumber">454</div>
        </div>
      </el-col>
    </el-row>
    <el-row :gutter="20" class="echartRow">
      <el-col :span="12">
        <div class="grid-content bg-purple" ref="chart1">
        </div>
      </el-col>
      <el-col :span="12">
        <div class="grid-content bg-purple" ref="chart2"></div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { hfMap } from '@/api'
export default {
  name: 'dashBoard',
  data() {
    return {
      // 第一个表单的
      option: {
        tooltip: {
          formatter: '{a} <br/>{b} : {c}%'
        },
        series: [
          {
            name: 'Pressure',
            type: 'gauge',
            detail: {
              formatter: '{value}%'
            },
            data: [
              {
                value: 50,
                name: 'SCORE'
              }
            ],
            progress: {
              show: true
            }
          }
        ],
        legendHoverLink: true
      },
      // 地图echart的
      option2: {
        aspectScale: 1,
        series: [{
          type: 'map',
          map: 'heiFei',
          name: '合肥市',
          label: {
            show: true
          }
        }]
      },
      myChart: null,
      myChart2: null,
      setTimeId: ''
    }
  },
  methods: {
    // 仪表盘组件
    initChart() {
      this.myChart = this.$echarts.init(this.$refs.chart1)
      this.myChart.setOption(this.option)
    },
    // 地图获取
    gethfMap() {
      hfMap().then(res => {
        this.$echarts.registerMap('heiFei', res.data)
        this.myChart2 = this.$echarts.init(this.$refs.chart2)
        this.myChart2.setOption(this.option2)
      })
    }
  },
  mounted() {
    this.gethfMap()
    this.initChart()
    window.onresize = () => {
      this.setTimeId = setTimeout(() => {
        this.myChart.resize()
        this.myChart2.resize()
      }, 10)
    }
  },
  beforeDestroy() {
    this.setTimeId = ''
    window.onresize = null
  }
}
</script>

<style lang="scss" scoped>
.topRow {
  margin-bottom: 20px;

  .grid-content {
    padding: 10px 20px 0 20px;
    height: 150px;
    background-color: #FFF;
    border-radius: 20px;
  }

  .inNumber {
    height: 100px;
    display: flex;
    align-items: center;
    margin-left: 60px;
    font-size: 24px;
    font-weight: bolder;
    color: rgb(99, 91, 91);
  }
}

.echartRow {
  .grid-content {
    height: 700px !important;
  }

  .bg-purple {
    background: #FFF;
  }
}
</style>
